<template>
    <div>
        <!-- 搜索区 -->
        <el-form :inline="true" size="small" ref="form" label-width="80px" >
            <el-form-item label="物品类型">
                <el-select v-model="params.type" placeholder="请选择" clearable>
                    <el-option v-for="item in goods" :key="item.id" :label="item.name" :value="item.name"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="关键字">
                <el-input v-model="params.name" placeholder="请输入关键字" clearable></el-input>
            </el-form-item>
        </el-form>

        <!-- 表格 -->
        <el-table :data="inventory.list" border style="width: 100%" size="small">
            <el-table-column fixed type="index" label="序号" width="80"></el-table-column>
            <el-table-column fixed label="申请人">
                <template slot-scope="scope">
                    {{scope.row.baseUser.realname}}
                </template>
            </el-table-column>
            <el-table-column prop="asset.code" label="物品编码"></el-table-column>
            <el-table-column prop="asset.name" label="物品名称"></el-table-column>
            <el-table-column prop="asset.type" label="物品类型"></el-table-column>
            <el-table-column prop="type" label="申请类别"></el-table-column>
            <el-table-column prop="asset.brand" label="品牌"></el-table-column>
            <el-table-column prop="asset.num" label="数量"></el-table-column>
            <el-table-column prop="estimatedPrice" label="预计单价"></el-table-column>
            <el-table-column prop="estimatedTotal" label="预计总价"></el-table-column>
            <el-table-column prop="estimatedUseTime" label="预计使用日期" width="180">
                <template slot-scope="scope">
                    {{scope.row.estimatedUseTime | dateFormat}}
                </template>
            </el-table-column>
            <el-table-column label="状态" fixed="right">
                <template slot-scope="scope">
                    <el-tag size="small">{{scope.row.status}}</el-tag>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页 -->
        <el-pagination
            layout="total, prev, pager, next"
            @current-change="pageHandler"
            :page-size="inventory.pageSize"
            :current-page="inventory.page"
            :total="inventory.total">
        </el-pagination>

    </div>
</template>

<script>
import request from '@/utils/request'
import qs from 'qs'
// import moment from 'moment'
import { mapActions ,mapState} from 'vuex'
export default {
    data() {
        return {
            fileList:[],
            inventory:[],
            params: {
                page: 1,
                pageSize: 5,
                applyforType: '申购',
                checkStatus: '通过'
            },
            goods: [],
            dialogVisible: false,
            title: '',
            form: {},
            userInfo:'',
            detailsForm: {},
            detailsDialogVisible: false,
            goods_row: '',
            batchDialogVisible: false,
            batchForm: {}
        }
    },
    created() {
        // 分页查询物品信息
        this.queryAsset(this.params)

        // 查询所有物品类型
        this.findAllGoods()

        // 获取经办人信息
        this.getInfo()

    },
    computed: {
        ...mapState('user',['user'])
    },

    watch: {
        params: {
            handler: function() {
                this.queryAsset(this.params)
            },
            deep: true
        }
    },

    methods: {
        ...mapActions('user',['getInfo']),
        handleRemove(file, fileList) {
            console.log(file, fileList);
        },
        handlePreview(file) {
            console.log(file);
        },
        handleExceed(files, fileList) {
            this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
        },
        beforeRemove(file, fileList) {
            return this.$confirm(`确定移除 ${ file.name }？`);
        },

        dateFormat(row, column, cellValue, index) {
            console.log(cellValue)
            return moment(cellValue).format('YYYY-MM-DD HH:mm:ss');
        },

        // 查询所有物品类型
        findAllGoods() {
            request.get("/assetType/findAll").then(res => {
                this.goods = res.data
            })
        },
        
        // 分页查询
        queryAsset() {
            request.post("/applyfor/pageQuery",qs.stringify(this.params)).then(res => {
                this.inventory = res.data
            })
        },

        // 分页
        pageHandler(page) {
            this.params.page = page
        }
    }
}
</script>

<style scoped>
    .el-row {
        margin-bottom: 1rem;
    }
    .warn {
        color: #ff0000;
        font-size: 12px;
    }
    .download {
        color: #51c1d9;
        margin: 1rem 0 1rem 1rem;
    }
    .download:hover {
        color: #85d3e4;
    }
    .el-table {
        margin-top: 1rem;
    }
    .el-form-item >>> .el-form-item__label {
        height: 30px;
    }
    .el-form-item__content {
        height: 30px;
    }
    .details_img {
        /* float:right; */
        border: 1px solid #ccc;
        width: 120px;
        height: 120px;
        position: absolute;
        top: 6rem;
        right: 4rem;
        border-radius: 5px;
        padding: 5px;
    }
    .details_img img {
        width: 110px;
        height: 110px;
    }
    .el-dialog__body {
        position: relative;
    }
    .el-form-item {
        margin-bottom: 0;
        height: 30px;
    }
    .el-icon-edit {
        margin: 0 .5rem;
    }
    .el-dialog__wrapper >>> .el-dialog__header{
        background-color: #55c1d9;
    }
    .el-dialog__wrapper >>> .el-dialog__header span,.el-dialog__wrapper >>> .el-icon-close{
        color: #fff;
    }
</style>